package com.leven.easyerp.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.leven.easyerp.dao.UserDao;
import com.leven.easyerp.entity.User;
import com.leven.easyerp.service.UserService;

/**
 * 用户管理
 * 
 * @author Leven.Chen
 */
@Service
public class UserServiceImpl extends BaseServiceImpl implements UserService {
	@Autowired
	private UserDao userDao;

	@Override
	public User createUser(User user) throws Exception {
		String id = (String) userDao.create(user);
		user.setId(id);
		return user;
	}

	public User getUser(String id) throws Exception {
		return userDao.get(User.class, id);
	}

	public User getUserByName(String username) {
		String hql = "from User username=?";
		Object[] args = new Object[] { username };
		List<User> userList = userDao.findObject(hql, args);
		if (!userList.isEmpty()) {
			return userList.get(0);
		} else {
			return null;
		}
	}
}
